package com.bing.api.controller;

import cn.hutool.core.util.IdUtil;
import com.bing.api.model.TestReq;
import com.bing.common.annotation.RLog;
import com.bing.common.domain.entity.ReqLog;
import com.bing.common.domain.mapper.ReqLogRepository;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description TODO
 * @Author Bing
 * @Date 2025/6/17 11:50
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private ReqLogRepository reqLogRepository;

    @RLog
    @GetMapping("/h1")
    public String hello1(TestReq testReq){
        return "hello1";
    }

    @RLog
    @PostMapping("/h2")
    @Transactional(rollbackFor = Exception.class)
    public String hello2(@RequestBody TestReq testReq){
        ReqLog reqLog = new ReqLog();
        reqLog.setId(IdUtil.getSnowflakeNextId()+"");
        reqLog.setMethod("POST");
        reqLog.setQueryParam("queryParam");
        reqLog.setBodyParam("bodyParam");
        reqLog.setResult("result");
        reqLog.setCreateTime(LocalDateTime.now());
        reqLog.setUri("uri");
        reqLog.setToken("token");
        reqLog.setContentType("contentType");
        reqLog.setHeader("header");
       // reqLogRepository.findById("1");
        reqLogRepository.save(reqLog);
        return "hello2";
    }

    @RLog
    @DeleteMapping("/h3/{id}")
    public String hello3(@PathVariable("id")Long id,@RequestParam("code") List<Long> code){
        return "hello3";
    }

    @RLog
    @PutMapping("/h4")
    public String hello4(TestReq testReq){
        return "hello4";
    }

    @RLog
    @PatchMapping("/h5")
    public String hello5(TestReq testReq){
        return "hello5";
    }
}